import mongoose from 'mongoose'
import conf from '../conf.js'

const { dbHost, dbPort } = conf
const dbName = 'mongoDB'
mongoose
  .connect(`mongodb://${dbHost}:${dbPort}/${dbName}`, {
    // useNewUrlParser: true,
    // useUnifiedTopology: true,
  })
  .catch(err => console.error(`${dbName}初始连接异常： ${err}`))

mongoose.connection.on('connected', () => console.log(`${dbName}已连接`))
mongoose.connection.on('disconnected', () => console.log(`${dbName}已断开连接`))
mongoose.connection.on('reconnected', () => console.log(`${dbName}尝试重新连接`))
mongoose.connection.on('error', err => console.error(`${dbName}连接异常： ${err}`))

export default mongoose
